
package net.pec.geotools_svg.svg_conversion;


import java.io.*;
import java.net.URL;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.geotools.data.*;
import org.geotools.feature.*;
import org.opengis.feature.simple.SimpleFeature;

import com.vividsolutions.jts.geom.*;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class GenerateTextElement {

private String fillColor = "green";
private String strokeColor = "black";
private double middleY;



  
public void createText(SimpleFeature feature, Document doc, Element gElement, Double midpoint, String Radius,  
		 int fillRed, int fillGreen, int fillBlue, double fillopacity, 
		int strokeRed, int strokeGreen, int strokeBlue,  double strokeopacity, int strokewidth, String clickEvent ) throws Exception {
  middleY = midpoint;
  Coordinate[] coord;
  Coordinate oneCrd = new Coordinate();
  String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
  Element pointElement = doc.createElementNS(svgNS, "circle");
  pointElement.setAttributeNS(null, "id", feature.getID());
  pointElement.setAttributeNS(null, "style","fill:rgb("+fillRed+","+fillBlue+","+fillGreen+")" +
	  		";fill-opacity:"+fillopacity+";stroke:rgb("+strokeRed+","+strokeBlue+","+strokeGreen+");stroke-width:"+strokewidth);
  pointElement.setAttributeNS(null, "r",Radius);
  
  if (clickEvent !=null){
	  pointElement.setAttributeNS(null, "onclick", clickEvent);
	  }
  
  Geometry geom = (Geometry) feature.getDefaultGeometry();
  String pointValues ="";
 
  			oneCrd = geom.getCoordinate();
  			double coorddiff = oneCrd.y - middleY;
 	  	   double newcoord = middleY-coorddiff;
	  	   //System.out.println(coorddiff+" "+newcoord+" "+oneCrd.y);
	  	 pointValues = Double.toString(oneCrd.x) ;
	  	pointElement.setAttributeNS(null, "cx", pointValues); 
	  	pointValues = Double.toString(newcoord) ;
	  	pointElement.setAttributeNS(null, "cy", pointValues); 
	
	
	  	gElement.appendChild(pointElement);
   
}



}